%detrend seasonal GDP
%Step 1: load data
Y = gdp;
N = length(Y);

figure(1)
plot(Y)
xlim([0,N])
set(gca,'XTick',[1:4:N])
set(gca,'XTickLabel',datestr(dates(1:4:N),10))
title('GDP')
hold on

%%
% Step 2. Detrend the data using a 5-term moving average.
sW13 = [1/8;repmat(1/4,3,1);1/8];
Ys = conv(Y,sW13,'same');
Ys(1:2) = Ys(3); Ys(N-1:N) = Ys(N-2);

xt = Y./Ys;

h = plot(Ys,'r','LineWidth',2);
legend(h,'5-Term Moving Average')
hold off

